package traveldream.ejb.sessionBean;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import traveldream.ejb.DTO.ExcursionDTO;
import traveldream.ejb.entities.Excursion;
import traveldream.ejb.interfaces.ExcursionEditBeanLocal;
import traveldream.ejb.interfaces.NotFindException;

/**
 * Session Bean implementation class ExcursionEditBean
 */
@Stateless
public class ExcursionEditBean implements ExcursionEditBeanLocal {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public ExcursionEditBean() {
        // TODO Auto-generated constructor stub
    }
    
    public ExcursionDTO find(int id) throws NotFindException{
    	Excursion e = em.find(Excursion.class, id);
    	try{
    		return e.convertToDTO();
    	}
    	catch(NullPointerException ex){
    		throw new NotFindException();
    	}
    }
    
    public void update(ExcursionDTO eDTO){
    	Excursion e = new Excursion(eDTO);
    	e.setId(eDTO.getId());
    	em.merge(e);
    }
}
